package algorithm;

/**
 * 二叉树
 *
 */
public class BinaryTree {

    public static void main(String[] args) {


    }

    public class TreeNode{
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = this.right = null;
        }
    }

    /**
     * 计算二叉树的高度
     * @param node
     * @return
     */
    public int treeHeight(TreeNode node){
        int height;
        if (node == null){
            height = 0;
        }
        int left = treeHeight(node.left);
        int right = treeHeight(node.right);

        if( Math.abs(left - right) > 1 ){
            height = 1;
        }
        return Math.max(left , right) + 1;
    }

    /**
     * 遍历二叉树，前序遍历
     * @param node
     */
    public void preOrder(TreeNode node){
        if (node == null){
            return;
        }

        preOrder(node.left);

        preOrder(node.right);
    }
}
